package com.example.juc;

import lombok.extern.slf4j.Slf4j;

/**
 * @Description
 * @Date 2021/7/24
 * @Created by Jonathan
 */
@Slf4j
public class Singleton {
    private static volatile Singleton INSTANCE;

    public static Singleton getInstance() {
        if (INSTANCE == null) {
            synchronized (Singleton.class) {
                if (INSTANCE == null) {
                    INSTANCE = new Singleton();
                }
            }
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        System.out.printf("Pi:%f\n", Math.PI);
        Singleton instance = getInstance();
        Singleton instance1 = getInstance();
        log.info("equal:{}", instance == instance1);
    }
}
